package com.sy.simpleegg.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.sy.simpleegg.room.entity.ControlBoardEntity

@Dao
interface ControlBoardDao {
    @Query("SELECT * FROM tb_control_board")
    fun getAll(): MutableList<ControlBoardEntity>?
    
    @Query("SELECT * FROM tb_control_board WHERE type = :type order by date asc limit 1")
    fun getLast(type: Int): MutableList<ControlBoardEntity>?

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(controlBoardEntity: ControlBoardEntity)

    @Delete
    fun delete(controlBoardEntity: ControlBoardEntity)

    @Query("DELETE FROM tb_control_board")
    fun deleteAll()

    @Query("SELECT * FROM tb_control_board WHERE type = :type AND date = :date")
    fun getDateData(type: Int, date: String): MutableList<ControlBoardEntity>?

    @Query("SELECT * FROM tb_control_board WHERE type = :type AND date BETWEEN :startDate AND :endDate")
    fun getBetweenDate(type: Int, startDate: String, endDate: String): MutableList<ControlBoardEntity>?

}